<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../resources/main.xhtml"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml">

    <ui:define name="content">
        <h:outputStylesheet library="css" name="estilo.css" />
        <h:outputScript library="js" name="javaScript.js" />
        <p:separator />
        <div class="pagina">
            Cadastro de Hospede
        </div>
        <p:separator />
        <h:form id="cadHosp" style="padding: 1px;">
            <p:growl id="msg1" />
            <h:inputHidden value="#{mbHospede.hospede.idHospede}" />
            <h:panelGrid columns="8">
                <h:outputLabel styleClass="lb" value="Nome.:" for="nome" />
                <h:inputText styleClass="tx" value="#{mbHospede.hospede.nome}" id="nome" 
                             onkeyup="this.value = this.value.toUpperCase()" size="50" 
                             required="true" requiredMessage="O nome é obrigatório!"/>

                <h:outputLabel value="Sexo.:" for="sexo" styleClass="lb" />                                
                <h:selectOneMenu id="sexo" value="#{mbHospede.hospede.sexo}" styleClass="tx" >
                    <f:selectItem itemValue="-" itemLabel="-" noSelectionOption="true" />
                    <f:selectItem itemValue="FEMININO" itemLabel="FEMININO"  />
                    <f:selectItem itemValue="MASCULINO" itemLabel="MASCULINO" />                    
                </h:selectOneMenu>

                <h:outputLabel styleClass="lb" value="CPF.:" for="cpf" />
                <h:inputText styleClass="tx" value="#{mbHospede.hospede.cpf}" id="cpf" size="17" 
                             onkeyup="cpfHospede(this.value);" maxlength="14" validatorMessage="CPF Inválido">
                    <f:validateRegex pattern="[\d]{3}.[\d]{3}.[\d]{3}-[\d]{2}$" />
                </h:inputText>

                <h:outputLabel styleClass="lb" value="RG.:" for="rg" />
                <h:inputText styleClass="tx" value="#{mbHospede.hospede.rg}" id="rg" size="17" />
            </h:panelGrid>
            <h:panelGrid columns="8">
                <h:outputLabel value="Orgão.:" for="ssp" styleClass="lb" />
                <h:inputText id="ssp" value="#{mbHospede.hospede.ssp}" styleClass="tx" size="20" onkeyup="this.value = this.value.toUpperCase()"/>
                <h:outputLabel styleClass="lb" value="DT. Nascimento:" for="nascimento" />
                <h:panelGroup>
                    <h:inputText styleClass="tx" value="#{mbHospede.hospede.nascimento}" id="nascimento" size="15" 
                                 onkeyup="dataNascHospede(this.value);" maxlength="10" converterMessage="Data não e válida" validator="dateValidator">
                        <f:convertDateTime pattern="dd/MM/yyyy" timeZone="America/Sao_Paulo"/>                        
                    </h:inputText>
                    <p:message for="nascimento" showDetail="true"/>
                </h:panelGroup>
                <h:outputLabel styleClass="lb" value="Telefone.:" for="telefone" />
                <h:inputText styleClass="tx" value="#{mbHospede.hospede.telefone}" id="telefone" 
                             onkeyup="telefoneHospede(this.value);" size="15" maxlength="13"/>

                <h:outputLabel styleClass="lb" value="Celular.:" for="celular" />
                <h:inputText styleClass="tx" value="#{mbHospede.hospede.celular}" id="celular" 
                             onkeyup="celularHospede(this.value);" size="15" maxlength="13"/>
            </h:panelGrid>
            <h:panelGrid columns="4">
                <h:outputLabel styleClass="lb" value="Endereço.:" for="endereco" />
                <h:inputText styleClass="tx" value="#{mbHospede.hospede.endereco}" id="endereco" onkeyup="this.value = this.value.toUpperCase()" size="50" />

                <h:outputLabel styleClass="lb" value="Bairro.:" for="bairro" />
                <h:inputText styleClass="tx" value="#{mbHospede.hospede.bairro}" id="bairro" onkeyup="this.value = this.value.toUpperCase()" size="50" />
            </h:panelGrid>
            <h:panelGrid columns="4">
                <h:outputLabel value="Município.:" for="municipio" styleClass="lb" />
                <h:selectOneMenu id="municipio" value="#{mbHospede.hospede.cidade.idCidade}" styleClass="tx" style="width: 220px;" required="true" requiredMessage="Campo município e obrigatório">
                    <f:selectItem itemValue="" itemLabel="-" /> 
                    <f:selectItems value="#{mbCidade.cidades}" var="c" itemValue="#{c.idCidade}" itemLabel="#{c.cidade}" />                    
                </h:selectOneMenu>

                <h:outputLabel styleClass="lb" value="CEP.:" for="cep" />
                <h:inputText styleClass="tx" value="#{mbHospede.hospede.cep}" id="cep" onkeyup="cepHospede(this.value);" size="15" maxlength="9" validatorMessage="CEP inválido">
                    <f:validateRegex pattern="[\d]{5}-[\d]{3}$" />
                </h:inputText>
            </h:panelGrid>
            <h:panelGrid columns="5">
                <h:outputLabel styleClass="lb" value="Mae.:" for="mae" />
                <h:inputText  styleClass="tx" value="#{mbHospede.hospede.nomeMae}" id="mae" onkeyup="this.value = this.value.toUpperCase()" size="50" />

                <h:outputLabel styleClass="lb" value="Recado.:" for="recado" />
                <h:inputText styleClass="tx" value="#{mbHospede.hospede.recado}" id="recado" onkeyup="this.value = this.value.toUpperCase()" size="50" />

                <h:panelGroup style="padding-left: 30px;">
                    <p:commandButton value="Cancelar" action="#{mbHospede.limparHospede}" immediate="true" ajax="false" update="@form"/>         
                    <p:commandButton value="Salvar" action="#{mbHospede.salvarHospede}" ajax="false" update="@form:tbHosp"/>
                </h:panelGroup>
            </h:panelGrid>
        </h:form>

        <p:separator />
        <div class="pagina">
            Lista de Hospedes
        </div>
        <p:separator />       
        <h:form id="frmPesqHospede">
            <fieldset>
                <legend style="font-size: 18px; color: #D20005">Pesquisar Hospedes</legend>
                <h:panelGrid columns="3">                   
                    <h:outputLabel value="Nome.:" styleClass="lb" style="float: left;"/>
                    <h:inputText value="#{mbHospede.pesquisa}" onkeyup="this.value = this.value.toUpperCase()" 
                                 styleClass="tx" style="color: #D20005;" size="40">                
                    </h:inputText>
                    <p:commandLink action="#{mbHospede.pesquisarHospede}" update=":tbHosp" title="Click para realizar a pesquisa" ajax="false">
                        <h:graphicImage library="img" name="lupa2.bmp" />
                    </p:commandLink>
                </h:panelGrid>
            </fieldset>
        </h:form>
        <h:form id="tbHosp">           
            <p:dataTable value="#{mbHospede.hospedes}" var="h" rendered="#{mbHospede.hospedes.size() > 0}" scrollable="true" scrollHeight="150">              
                <p:column headerText="Cod" style="text-align: center; font-size: 12px;">
                    <h:outputText value="#{h.idHospede}" styleClass="txt" />
                </p:column>
                <p:column headerText="Nome" style="text-align: left; font-size: 12px;">
                    <h:outputText value="#{h.nome}" styleClass="txt" />
                </p:column>
                <p:column headerText="Sexo" style="text-align: left; font-size: 12px;">
                    <h:outputText value="#{h.sexo}" styleClass="txt" />
                </p:column>
                <p:column headerText="CPF" style="text-align: left; font-size: 12px;">
                    <h:outputText value="#{h.cpf}" styleClass="txt" />
                </p:column>
                <p:column headerText="DT. Nasc" style="text-align: left; font-size: 12px;">
                    <h:outputText value="#{h.nascimento}" styleClass="txt">
                        <f:convertDateTime pattern="dd/MM/yyyy" />
                    </h:outputText>
                </p:column>
                <p:column headerText="Endereço" style="text-align: left; font-size: 12px;">
                    <h:outputText value="#{h.endereco}" styleClass="txt" />
                </p:column>
                <p:column headerText="Município" style="text-align: left; font-size: 12px;">
                    <h:outputText value="#{h.cidade.cidade}" styleClass="txt" />
                </p:column>               
                <p:column headerText="Alterar" style="text-align: center; font-size: 12px;">
                    <p:commandLink action="#{mbHospede.alterarHospede(h.idHospede)}" styleClass="txt" ajax="false" update="@form:cadHosp" title="Alterar">
                        <h:graphicImage library="img" name="edicao.png" />
                    </p:commandLink>
                </p:column>               
                <p:column headerText="Entrada" style="text-align: center; font-size: 12px;">
                    <p:commandLink action="#{mbHospedagem.checkinHospede}" styleClass="txt" ajax="false" title="Registrar Entrada">
                        <f:setPropertyActionListener target="#{mbHospedagem.idHospede}" value="#{h.idHospede}" />
                        <h:graphicImage library="img" name="cama.bmp" />
                    </p:commandLink>
                </p:column>               
            </p:dataTable>
        </h:form>       
    </ui:define>
</ui:composition>
